<?php
class KillTheDragon{
        static public function shortenText($text, $length){
            preg_match('!.{0,'.$length.'}\s!si', $text, $match);

            if(count($match) != 0)
                return $match[0].'...';

            return $text;
        }
        static public function cleanReturn($text){
            $text = preg_replace('#\n#', '\\', $text);
            $text = preg_replace('#<br\>#', '\\', $text);
            return $text;
        }
        static public function getDayPeriod(){
            $time = date('H');
            if($time > 19 || $time < 7)
                return 'night';
            else
                return 'day';
        }
	static public function slugify($text){
		// replace non letter or digits by -
		  $text = preg_replace('#[^\\pL\d]+#u', '-', $text);
		 
		  // trim
		  $text = trim($text, '-');
		 
		  // transliterate
		  if (function_exists('iconv'))
		  {
			$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
		  }
		 
		  // lowercase
		  $text = strtolower($text);
		 
		  // remove unwanted characters
		  $text = preg_replace('#[^-\w]+#', '', $text);
		 
		  if (empty($text))
		  {
			return 'n-a';
		  }
		 
		  return $text;
	}
        static public function removeAccents($text){
            if (function_exists('iconv'))
            {
		$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
            }
             $text = preg_replace('#\'#', '', $text);
            return $text;
        }
        static public function convertToJSArray($arr){
            $js = "{
                ";
            foreach($arr as $key => $value){
                $js .= $key.' : ';
                if(is_numeric($value))
                    $js .= $value;
                else if(is_string($value))
                    $js .= '"'.$value.'"';
                else if(!isset($value))
                    $js .= '""';
                else
                    $js .= $value;
                $js .= ',
                    ';
            }
            $js .= "}";
            return $js;
        }
}

?>